package com.uh.calculation.inter.imp;


import com.alibaba.fastjson.JSONObject;
import com.uh.calculation.bean.OperatorVal;
import com.uh.calculation.bean.WarnJiSuanBean;
import com.uh.calculation.inter.Warn;
import com.uh.calculation.operator.*;
import com.uh.calculation.util.GetOrganization;
import com.uh.microservice.core.dao.JdbcDao;
import com.uh.summary.enums.RuleEnum;

import java.util.Date;
import java.util.List;
import java.util.Map;

public class GongyeImp implements Warn {

    //1-本月 营业收入修改比例超过15%，计预警因子50。
    //年报营业收入修改比例超过15%，计预警因子50。（此条仅用于4月年报出来时，但一直触发到该企业被核查或检查为止）
    private String  xgfd="[{dimension:\"A\",field:\"$NEW_VALUE;$NEW_VALUE#m\",formulaBeans:[{formula:\"($NEW_VALUE@$NEW_VALUE#m)/$NEW_VALUE#m>0.15|50\"}]}]";
    private String  xgcs="[{dimension:\"A\",field:\"$NEW_VALUE\",formulaBeans:[{formula:\"$NEW_VALUE>3|50\"}]}]";


    /////////////////////////////////////////////////////////////////////////////////////////////////////异常
    //运营状态
    private String yyzt = "[{\"dimension\":\"B\",\"field\":\"201-1_M55\",\"formulaBeans\":[{\"formula\":\"201-1_M55=2|50\",\"formula\":\"201-1_M55=4|50\",\"formula\":\"201-1_M55=5|50\",\"formula\":\"201-1_M55=6|50\",\"formula\":\"201-1_M55=7|50\"}]}]";
    //小升规
    private String xsg = "[{\"dimension\":\"B\",\"field\":\"B103-2_M32\",\"formulaBeans\":[{\"formula\":\"B103-2_M32<=22000|50\"},{\"formula\":\"B103-2_M32<=25000|30\"}]}]";
    private JdbcDao jdbcDao;
    public WarnJiSuanBean warnJiSuan = null;
    //通用表
    List<Map<String, Object>> G201_1ls = null;
    List<Map<String, Object>> B103_2s = null;
    List<Map<String, Object>> TJR201_1ls = null;
    List<Map<String, Object>> HJ_ls = null;
    List<Map<String, Object>> HJN_ls = null;
    List<Map<String, Object>> F201_1ls = null;

    @Override
    public Integer jisuan(WarnJiSuanBean warnJiSuan) {
        this.warnJiSuan = warnJiSuan;
        this.jdbcDao = warnJiSuan.getJdbcDao();
        GetOrganization getOrganization = new GetOrganization(jdbcDao);
        /**
         * 当前所用所有list一次取出
         */
        Date lastTime = warnJiSuan.getLastTime();

        G201_1ls = getOrganization.getFieldName("201-1", warnJiSuan.getYear(), warnJiSuan.getSurveyobjectid());
        B103_2s = getOrganization.getFieldName("B103-2", warnJiSuan.getYear(), warnJiSuan.getSurveyobjectid());
        TJR201_1ls = getOrganization.getFieldName_TJRY("201-1", warnJiSuan.getYear(), warnJiSuan.getSurveyobjectid(), lastTime);



        HJ_ls =  getOrganization.gethj("et_8600000002021110107720426", warnJiSuan.getSurveyobjectid());
        //年报
        HJN_ls =  getOrganization.gethj("et_8600000002021110107720943", warnJiSuan.getSurveyobjectid());

        F201_1ls = getOrganization.getFieldName("201-1", warnJiSuan.getYear(), warnJiSuan.getSurveyobjectid());

        warnJiSuan.setF201_1ls(F201_1ls);


        String year_is_month = getOrganization.gethc(warnJiSuan.getSurveyobjectid());//核查时间
        warnJiSuan.setYear_is_month(year_is_month);




        HjOperator hjOperator = new HjOperator(jdbcDao, warnJiSuan);
        List<OperatorVal> list = JSONObject.parseArray(xgfd, OperatorVal.class);
        //修改一
        warnJiSuan.setIs_hc(false);
        warnJiSuan.setWarnType(RuleEnum.INDUSTRY_EDIT_WEIGHT.getCode());//风险因子类型
        hjOperator.jisuan(HJ_ls, list,"本月;工业总产值(当年价格);千元|1-本月;工业总产值(当年价格);千元");
        //hjOperator.jisuan(HJ_ls, list,"1-本月;工业总产值(当年价格);千元");

        warnJiSuan.setIs_hc(true);
        hjOperator.jisuan(HJN_ls, list,"本年;工业总产值(当年价格);千元|本年;营业收入;千元");
        //hjOperator.jisuan(HJN_ls, list,"本年;营业收入;千元");


        list = JSONObject.parseArray(xgcs, OperatorVal.class);
        HjNumOperator  hjNumOperator = new HjNumOperator(jdbcDao, warnJiSuan);
        warnJiSuan.setIs_hc(false);
        warnJiSuan.setWarnType(RuleEnum.INDUSTRY_EDIT_FREQUENCY_FACTOR_MONTH_DATA.getCode());//风险因子类型
        hjNumOperator.jisuan(HJN_ls, list,"本月;工业总产值(当年价格);千元|1-本月;工业总产值(当年价格);千元");
        //hjNumOperator.jisuan(HJN_ls, list,"1-本月;工业总产值(当年价格);千元");

        //
        //运营状态
        YyztOperator yyztOperator = new YyztOperator(jdbcDao, warnJiSuan);
        list = JSONObject.parseArray(yyzt, OperatorVal.class);
        warnJiSuan.setIs_hc(false);
        warnJiSuan.setYear_is_month(year_is_month);
        warnJiSuan.setWarnType(RuleEnum.INDUSTRY_ABNORMAL_MANAGE_FACTOR_DATA.getCode());//风险因子类型
        yyztOperator.jisuanYyzt(G201_1ls, list);
        //统计人员变动
        TjryOperator tjryOperator = new TjryOperator(jdbcDao, warnJiSuan);
        warnJiSuan.setIs_hc(false);
        warnJiSuan.setWarnType(RuleEnum.INDUSTRY_ABNORMAL_STATISTICS_FACTOR_DATA.getCode());//风险因子类型
        tjryOperator.jisuan(TJR201_1ls, "M84", "B");//填表人字段 201-1表2021年-M84

        //小升规
        XsgOperator xsgOperator = new XsgOperator(jdbcDao, warnJiSuan);
        list = JSONObject.parseArray(xsg, OperatorVal.class);
        warnJiSuan.setIs_hc(false);
        /**风险因子类型*/
        warnJiSuan.setWarnType(RuleEnum.INDUSTRY_ABNORMAL_SMALL_FACTOR_DATA.getCode());
        xsgOperator.jisuanMaoyiZc(B103_2s, list);
        return null;
    }
}
